<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>部门信息配置</title>
		<%@include file="/WEB-INF/ibnms/common/jqgrid.jsp"%>
		<jsp:include page="/WEB-INF/ibnms/common/configinclude.jsp"></jsp:include>
		<%@ include file="/WEB-INF/ibnms/common/formValidation.jsp"%>
	</head>

<body>

	<div class="form-wrapper">
		<div class="form-title">
			<span class="ttcorner"></span>
			<h3>
				<span class="text">部门信息配置</span>
			</h3>
		</div>
		<div class="box-in">
			<form id="theForm" action="<s:url action="saveDepart"/>">
				<input type="hidden" name="deptForm.ISMP_JSP_COMMAND" value="${deptForm.ISMP_JSP_COMMAND}"></input>
				<input type="hidden" id="deptForm.SUPER_DEPT_ID" name="deptForm.SUPER_DEPT_ID" value="${deptForm.SUPER_DEPT_ID}"></input>
				<input type="hidden" name="deptForm.deptId" value="${deptForm.deptId}"></input>

				<table id="moduleEditTab" border="0" cellspacing="0"
					cellpadding="0" class="table-03">
					<tr>
						<td class="monitor_bg1" height="13" width="300px" align="right" nowrap>
							部门名称:
						</td>
						<td>
							<input type="text" name="deptForm.deptName" id="deptName"
								class="validate[required]" value="${deptForm.deptName}"></input>
							<font color="red">*</font>
						</td>
					</tr>
					<tr>
						<td class="monitor_bg1" height="13" align="right" nowrap>
							部门编码：
						</td>
						<td>
							<input type="text" name="deptForm.deptCode" id="deptCode" class="validate[maxSize,10]"
								value="${deptForm.deptCode}"></input>
						</td>
					</tr>
					<tr>
						<td class="monitor_bg1" height="13" align="right" nowrap>
							注释：
						</td>
						<td>
							<input type="text" name="deptForm.deptDesc" id="deptDesc" size=100
								value="${deptForm.deptDesc}"></input>
						</td>
					</tr>
			   		<tr>
			   			<td class="monitor_bg1" height="13" align ="right" nowrap>
			   				<input type="button" id="btn-mgr" class="btn-style" width="100px" value="部门管理员" />
			   			</td>
			   		</tr>
				</table>
				<div id="mgrDiv" style="display:none">
					<table id="mgrTable" border="0" cellspacing="0" cellpadding="0" class="table-03">
						<tr>
							<td class="monitor_bg1" height="13" width="300px" align="right" nowrap>
								部门管理员：
							</td>
							<td>
								<input type="text" name="deptForm.mgrName" id="mgrName" onclick="selectUser();"
									value="${deptForm.mgrName}"></input>
		         				<input type="hidden" id="mgrId" name="deptForm.mgrId" value="${deptForm.mgrId}"/>
		         				<input type="button" class="btn-style02" value="请空" onclick="clearMgr()" />
							</td>
						</tr>
						<tr>
				         	 <td class="monitor_bg1" height="13" align ="right" nowrap>
				         	 选择管理员可以分配的角色：
					         </td>
					         <td>
					         	  <select name="selectRoles" id="selectRoles" multiple="multiple" style="width:20%"> 
								       	<s:iterator value="roleList" var="role">
								       		<s:if test='%{deptForm.roleIds.contains(ROLE_ID)}'>
								           		<option value="<s:property value="#role.ROLE_ID"/>" selected><s:property value="#role.ROLE_NAME"/></option>
								           	</s:if>
								           	<s:if test='%{deptForm.roleIds==null || !deptForm.roleIds.contains(ROLE_ID)}'>
								           		<option value="<s:property value="#role.ROLE_ID"/>"><s:property value="#role.ROLE_NAME"/></option>
								           	</s:if>
								         </s:iterator>
							       </select>
					         </td>
				   		</tr>
				   		<tr>
				         	 <td class="monitor_bg1" height="13" align ="right" nowrap>
				         	 选择管理员可以分配的工作组：
					         </td>
					         <td>
					         	  <select name="selectWorkGroups" id="selectWorkGroups" multiple="multiple" style="width:20%"> 
								       	<s:iterator value="workGroupList" var="workGroup">
								       		<s:if test='%{deptForm.workGroupIds.contains(WORKGROUP_ID)}'>
								           		<option value="<s:property value="#workGroup.WORKGROUP_ID"/>" selected><s:property value="#workGroup.WORKGROUP_NAME"/></option>
								           	</s:if>
								           	<s:if test='%{deptForm.workGroupIds==null || !deptForm.workGroupIds.contains(WORKGROUP_ID)}'>
								           		<option value="<s:property value="#workGroup.WORKGROUP_ID"/>"><s:property value="#workGroup.WORKGROUP_NAME"/></option>
								           	</s:if>
								         </s:iterator>
							       </select>
					         </td>
				   		</tr>
					</table>
				</div>
				<div class="block03">
					<input type="button" id="btn-save" class="btn-style02" value="保存" />
					&nbsp;&nbsp;
					<input type="button" class="btn-style02" value="重置"
						onclick="resetForm()" />
					&nbsp;&nbsp;
					<input type="button" class="btn-style02" value="返回"
						onclick="back()" />
				</div>
			</form>
		</div>
	</div>
</body>
	<script language="javascript">
		$(document).ready(function(){
			if($("#mgrId").val()!=""){
				$("#mgrDiv").show();
			}
		});
		
		function selectUser(){
			var selectUser = window.showModalDialog('<%=application.getContextPath()%>/loadUserManage.do?type=select','选择用户','help:no;scroll:no;status:no;dialogHeight:600px;dialogWidth:900px');
	   		if(selectUser!=undefined){
	   			var id = "";
	   			var name = "";
	   			for (var one in selectUser){
                   	id = id + selectUser[one].LOGIN_ID + ",";
                   	name = name + selectUser[one].NAME + ",";
                }
                if(id.length>0){
                	id = id.substring(0,id.length-1);
                	name = name.substring(0,name.length-1);
                }
				$("#mgrId").val(id);
				$("#mgrName").val(name);
			}
		} 
		
		function clearMgr(){
			$("#mgrId").val('');
			$("#mgrName").val('');
			$("#mgrDiv").hide();
		}
			
		function back(){
			var parentId = $("input[name='deptForm.SUPER_DEPT_ID']").val();
			window.location.href="<s:url action='loadDeptList.do?deptForm.SUPER_DEPT_ID="+parentId+"' namespace='/'/>";
		}
		function resetForm(){
			$('#theForm')[0].reset();
		}
        $("#btn-save").click(function() {
        	if($("#mgrName").val()!=null && $("#mgrName").val()!=""){
        		if($("#selectRoles").val()==null){
        			alert("请选择管理员可分配的角色");
        			return false;
        		}
        	}
			$("#theForm").submit();
		});
		
		$("#theForm").validationEngine().ajaxForm({
			type:"post",
			beforeSubmit:function() {
		        $("body").mask('正在保存,请稍后...');
			},
			success:function(data) {
				if (data == "true"){
					alert('保存成功!');
					parent.refreshNode();
					back();
				} else {
					alert('保存失败：'+data);
				}
			},
			error:function(xhr){
				$("body").unmask();
			   show_error(xhr);
			}
		});	
		
		$("#btn-mgr").click(function() {
			$("#mgrDiv").show();
		});
		
    </script>
</html>
